package cn.zxh.improvement.common.core.function;

import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;

/**
 * 函数工具
 *
 * @author zxh
 * @since 2023/5/11 15:33:18
 */
public interface FunctionExceptionUtil {

    /**
     * 包装 ConsumerWithException
     *
     * @param consumer Consumer
     * @param <T>      入参类型
     * @return ConsumerWithException
     */
    static <T> Consumer<T> consumer(ConsumerWithException<T> consumer) {
        return consumer;
    }

    /**
     * 包裹 FunctionWithException
     *
     * @param function Function
     * @param <T>      入参类型
     * @param <R>      出参类型
     * @return FunctionWithException
     */
    static <T, R> Function<T, R> function(FunctionWithException<T, R> function) {
        return function;
    }

    /**
     * 包裹 predicate 为 PredicateWithException
     *
     * @param predicate Predicate
     * @param <T>       入参类型
     * @return PredicateWithException
     */
    static <T> Predicate<T> predicate(PredicateWithException<T> predicate) {
        return predicate;
    }

    /**
     * 包裹 SupplierWithException
     *
     * @param supplier Supplier
     * @param <T>      入参类型
     * @return SupplierWithException
     */
    static <T> Supplier<T> supplier(SupplierWithException<T> supplier) {
        return supplier;
    }
}
